package action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import bean.DB;
import bean.Exam;

public class AdminExam extends ActionSupport{
	Connection con=null;
	PreparedStatement pst=null;
	ResultSet rs=null;
	List<Exam> allexamlist=new ArrayList<>();
	public String allexam() throws SQLException {
		allexamlist.clear();
	String sql="select * from examtable";
		DB db=new DB();
		con=db.getCon();
		pst=con.prepareStatement(sql);
		rs=pst.executeQuery();
		while(rs.next()) {
			Exam exam=new Exam();
			exam.setExamid(rs.getInt("examid"));
			exam.setExamname(rs.getString("examname"));
			exam.setStarttime(rs.getString("starttime"));
			exam.setAutostart(rs.getString("autostart"));
			exam.setExampaper(rs.getString("exampaper"));
			exam.setStarted(rs.getString("started"));
			exam.setFinished(rs.getString("finished"));
			exam.setArchived(rs.getString("archived"));
			exam.setCleaned(rs.getString("cleaned"));
			exam.setExamcreator(rs.getString("examcreator"));
			exam.setExamining(rs.getString("examining"));
			allexamlist.add(exam);
		}
		ActionContext.getContext().put("allexamlist",allexamlist);
		rs.close();
		pst.close();
		con.close();
		return SUCCESS;
	}

}
